//
// Created by hps on 24-4-1.
//

#ifndef FILEMANAGER_H
#define FILEMANAGER_H

#include "HeadFiles.h"
#include "Config.h"
#include "../utils/utils.h"
#include "TreeWidgetItem.h"

namespace hps {


class FileManager : public QTreeWidget{
    Q_OBJECT
public:
Q_SIGNALS:
    void rightButtonClicked(QTreeWidgetItem* item);

protected:
    void mousePressEvent(QMouseEvent *event) override {
        if (event->button() == Qt::RightButton) {
            QTreeWidgetItem* item = itemAt(event -> pos());
            emit rightButtonClicked(item);
        }
        QTreeWidget::mousePressEvent(event);
    }

public:
    FileManager();
    void init();
    void loadNoteBook(QString _dir, QTreeWidgetItem* parentItem);
    void freeItems();
private:
    std::stack<QTreeWidgetItem*> m_items; // 用于关闭页面之后的统一释放内存
    bool m_hasLoadBook = false;
    QTreeWidgetItem* m_parentItem;
    QString m_dir;
};

} // hps

#endif //FILEMANAGER_H
